
using Youz.Common.DBUtility;
using Youz.Common.Entity;
using System;
using System.Data;
using System.Data.SqlClient;
using System.Text;

namespace Youz.Common.DAL
{
    /// <summary>
    /// Log_ErrorLog Data Class
    /// </summary>
    public partial class Log_ErrorLogDAL : BaseDAL
    {
		private DbHelperSQL DbHelperSQL = new DbHelperSQL();
        public string TableName = "Log_ErrorLog";

        public Log_ErrorLogDAL()
        {}

        #region  成员方法
        /// <summary>
        ///  新增一条数据
        /// </summary>
        public bool Add(Log_ErrorLog model)
        {
            StringBuilder strSql = new StringBuilder();
			
            strSql.Append("insert into [Log_ErrorLog](");
            strSql.Append("[ErrorLogID],[Host],[RequestType],[LoginType],[AbsolutePath],[PostData],[QueryString],[UserHostAddress],[UserAgent],[Source],[TargetSite],[ErrMess],[BaseErrMess],[StackTraceErr],[CreateTime]");
            strSql.Append(") values (");
            strSql.Append("@ErrorLogID,@Host,@RequestType,@LoginType,@AbsolutePath,@PostData,@QueryString,@UserHostAddress,@UserAgent,@Source,@TargetSite,@ErrMess,@BaseErrMess,@StackTraceErr,@CreateTime");
            strSql.Append(")");
			
            SqlParameter[] parameters = {
                  
                    new SqlParameter("@ErrorLogID", model.ErrorLogID),
                    new SqlParameter("@Host", model.Host),
                    new SqlParameter("@RequestType", model.RequestType),
                    new SqlParameter("@LoginType", model.LoginType),
                    new SqlParameter("@AbsolutePath", model.AbsolutePath),
                    new SqlParameter("@PostData", model.PostData),
                    new SqlParameter("@QueryString", model.QueryString),
                    new SqlParameter("@UserHostAddress", model.UserHostAddress),
                    new SqlParameter("@UserAgent", model.UserAgent),
                    new SqlParameter("@Source", model.Source),
                    new SqlParameter("@TargetSite", model.TargetSite),
                    new SqlParameter("@ErrMess", model.ErrMess),
                    new SqlParameter("@BaseErrMess", model.BaseErrMess),
                    new SqlParameter("@StackTraceErr", model.StackTraceErr),
                    new SqlParameter("@CreateTime", model.CreateTime)
            };

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        /// <summary>
        ///  保存一条数据
        /// </summary>
        public bool Update(Log_ErrorLog model)
        {
            StringBuilder strSql = new StringBuilder();
			
            strSql.Append("update [Log_ErrorLog] set ");
            strSql.Append("[Host]=@Host,[RequestType]=@RequestType,[LoginType]=@LoginType,[AbsolutePath]=@AbsolutePath,[PostData]=@PostData,[QueryString]=@QueryString,[UserHostAddress]=@UserHostAddress,[UserAgent]=@UserAgent,[Source]=@Source,[TargetSite]=@TargetSite,[ErrMess]=@ErrMess,[BaseErrMess]=@BaseErrMess,[StackTraceErr]=@StackTraceErr,[CreateTime]=@CreateTime");
            strSql.Append(" where [ErrorLogID]=@ErrorLogID");
			
            SqlParameter[] parameters = {
                  
                    new SqlParameter("@ErrorLogID", model.ErrorLogID),
                    new SqlParameter("@Host", model.Host),
                    new SqlParameter("@RequestType", model.RequestType),
                    new SqlParameter("@LoginType", model.LoginType),
                    new SqlParameter("@AbsolutePath", model.AbsolutePath),
                    new SqlParameter("@PostData", model.PostData),
                    new SqlParameter("@QueryString", model.QueryString),
                    new SqlParameter("@UserHostAddress", model.UserHostAddress),
                    new SqlParameter("@UserAgent", model.UserAgent),
                    new SqlParameter("@Source", model.Source),
                    new SqlParameter("@TargetSite", model.TargetSite),
                    new SqlParameter("@ErrMess", model.ErrMess),
                    new SqlParameter("@BaseErrMess", model.BaseErrMess),
                    new SqlParameter("@StackTraceErr", model.StackTraceErr),
                    new SqlParameter("@CreateTime", model.CreateTime)
            };

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        /// <summary>
        /// 删除一条数据
        ///</summary>
        public bool Delete(Guid ErrorLogID)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete from [Log_ErrorLog] ");
            strSql.Append(" where [ErrorLogID]=@ErrorLogID");
			
            SqlParameter[] parameters = {
			
                new SqlParameter("@ErrorLogID", ErrorLogID)             
              
            };

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Log_ErrorLog Get(Guid ErrorLogID)
        {
            StringBuilder strSql = new StringBuilder();
			
            strSql.Append("select  top 1 * from [Log_ErrorLog] ");
            strSql.Append(" where [ErrorLogID]=@ErrorLogID");
			
            SqlParameter[] parameters = {
			
                new SqlParameter("ErrorLogID", ErrorLogID)             
              
            };

            DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);
            if (ds.Tables[0].Rows.Count > 0)
            {
                return Get(ds.Tables[0].Rows[0]);
            }
            else
            {
                return null;
            }
        }

		/// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Log_ErrorLog Get(DataRow row)
        {
            if (row == null) return null;

            Log_ErrorLog model = new Log_ErrorLog();
	
            
            if (row["ErrorLogID"] != DBNull.Value)
            {
                model.ErrorLogID = (Guid)row["ErrorLogID"];
            }      
            
            if (row["Host"] != DBNull.Value)
            {
                model.Host = (String)row["Host"];
            }      
            
            if (row["RequestType"] != DBNull.Value)
            {
                model.RequestType = (String)row["RequestType"];
            }      
            
            if (row["LoginType"] != DBNull.Value)
            {
                model.LoginType = (Int32)row["LoginType"];
            }      
            
            if (row["AbsolutePath"] != DBNull.Value)
            {
                model.AbsolutePath = (String)row["AbsolutePath"];
            }      
            
            if (row["PostData"] != DBNull.Value)
            {
                model.PostData = (String)row["PostData"];
            }      
            
            if (row["QueryString"] != DBNull.Value)
            {
                model.QueryString = (String)row["QueryString"];
            }      
            
            if (row["UserHostAddress"] != DBNull.Value)
            {
                model.UserHostAddress = (String)row["UserHostAddress"];
            }      
            
            if (row["UserAgent"] != DBNull.Value)
            {
                model.UserAgent = (String)row["UserAgent"];
            }      
            
            if (row["Source"] != DBNull.Value)
            {
                model.Source = (String)row["Source"];
            }      
            
            if (row["TargetSite"] != DBNull.Value)
            {
                model.TargetSite = (String)row["TargetSite"];
            }      
            
            if (row["ErrMess"] != DBNull.Value)
            {
                model.ErrMess = (String)row["ErrMess"];
            }      
            
            if (row["BaseErrMess"] != DBNull.Value)
            {
                model.BaseErrMess = (String)row["BaseErrMess"];
            }      
            
            if (row["StackTraceErr"] != DBNull.Value)
            {
                model.StackTraceErr = (String)row["StackTraceErr"];
            }      
            
            if (row["CreateTime"] != DBNull.Value)
            {
                model.CreateTime = (DateTime)row["CreateTime"];
            }      
            

            return model;
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet Gets(string sqlWhere)
        {
            StringBuilder strSql = new StringBuilder();
			
            strSql.Append("select * from [Log_ErrorLog] ");
            if (sqlWhere.Trim() != "")
            {
                strSql.Append(" where " + sqlWhere);
            }
            
            return DbHelperSQL.Query(strSql.ToString());
        }

        /// <summary>
        /// 获得前几行数据
        /// </summary>
        public DataSet Gets(int Top, string sqlWhere, string filedOrder)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select ");
            if (Top > 0)
            {
                strSql.Append(" top " + Top.ToString());
            }
            strSql.Append(" *  FROM [Log_ErrorLog] ");
			
            if (sqlWhere.Trim() != "")
            {
                strSql.Append(" where " + sqlWhere);
            }
            if(filedOrder.Trim() != "")
            {
                strSql.Append(" order by " + filedOrder);
            }
			
            return DbHelperSQL.Query(strSql.ToString());
        }

        /// <summary>
        /// 获取记录总数
        /// </summary>
        public int GetRecordCount(string sqlWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select count(1) FROM [Log_ErrorLog] ");
            if (sqlWhere.Trim() != "")
            {
                strSql.Append(" where " + sqlWhere);
            }
            object obj = DbHelperSQL.GetSingle(strSql.ToString());
            if (obj == null)
            {
                return 0;
            }
            else
            {
                return Convert.ToInt32(obj);
            }
        }

        /// <summary>
        /// 获得数据列表分页
        /// </summary>
        public DataTable Gets(string sqlWhere, int pageindex, int pagesize, out int total, params SqlParameter[] cmdParms)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append(" SELECT * FROM [Log_ErrorLog]  ");
            if (sqlWhere.Trim() != "")
            {
                strSql.Append(" where " + sqlWhere);
            }

            int count = 0;
            DataTable dt = DbHelperSQL.GetPager(pageindex, pagesize, "" + strSql + "", "order by CreateTime desc ", out count, cmdParms);
            total = count;
            return dt;
        }
      #endregion  成员方法
    }
}


  